<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<!-- HTML file produced from file: manual.tex --
 -- using Hyperlatex v 2.3.1 (c) Otfried Cheong--
 -- on Emacs 21.4 (patch 12) "Portable Code" XEmacs Lucid, Wed Jun  2 18:57:17 2004 -->
<HEAD>
<TITLE>Scheme 48 Manual -- Regular expressions</TITLE>

</HEAD><BODY BGCOLOR="#ffffff">
<EM>Scheme 48 Manual</EM> | <A HREF="s48manual.html#top_node">Contents</A> | In Chapter: <A HREF="s48manual_78.html">Access to POSIX</A><BR>Previous: <A HREF="s48manual_87.html">Regular expressions</A> | Next: <A HREF="s48manual_87.html">Regular expressions</A>
<H2>Regular expressions</H2>
The procedures in this section provide access to POSIX regular expression
 matching.
The regular expression syntax and semantics are far too complex to
 be described here.
Because the C interface uses zero bytes for marking the ends of strings,
 patterns and strings that contain zero bytes will not work correctly.
<P>These procedures are in structures <CODE>posix-regexps</CODE> and <CODE>posix</CODE>.
<P>An abstract data type for creating POSIX regular expressions is
 described in section&nbsp;<A HREF="s48manual_55.html">*</A>.
<P><UL><LI><CODE>(make-regexp<I>&nbsp;string&nbsp;.&nbsp;regexp-options</I>)&nbsp;-&gt;&nbsp;<I>regexp</I></CODE><A NAME="1">&nbsp;</A>
<LI><table border=0 cellspacing=0 cellpadding=0 width=80%>
<tr> <td><CODE>(regexp-option <CODE><I>option-name</I></CODE>)&nbsp;-&gt;&nbsp;<I>regexp-option</I></CODE></td> <td align=right>syntax</td></tr></table>
</UL>
<CODE>Make-regexp</CODE> makes a new regular expression, using <CODE><I>string</I></CODE>
 as the pattern.
The possible option names are:
<P><BLOCKQUOTE><CENTER>
<TABLE><TR><TD COLSPAN="1" ALIGN="LEFT">

<CODE>extended</CODE> </TD><TD COLSPAN="1" ALIGN="LEFT"> use the extended patterns </TD></TR>
<TR><TD COLSPAN="1" ALIGN="LEFT">
<CODE>ignore-case</CODE> </TD><TD COLSPAN="1" ALIGN="LEFT"> ignore case when matching </TD></TR>
<TR><TD COLSPAN="1" ALIGN="LEFT">
<CODE>submatches</CODE> </TD><TD COLSPAN="1" ALIGN="LEFT"> report submatches </TD></TR>
<TR><TD COLSPAN="1" ALIGN="LEFT">
<CODE>newline</CODE> </TD><TD COLSPAN="1" ALIGN="LEFT"> treat newlines specially 
</TD></TR></TABLE>

</CENTER></BLOCKQUOTE>
<P>The regular expression is not compiled until it matched against a string,
 so any errors in the pattern string will not be reported until that
 point.
<P><UL><LI><CODE>(regexp?<I>&nbsp;x</I>)&nbsp;-&gt;&nbsp;<I>boolean</I></CODE><A NAME="2">&nbsp;</A>
</UL>
This is a predicate for regular expressions.
<P><UL><LI><CODE>(regexp-match<I>&nbsp;regexp&nbsp;string&nbsp;start&nbsp;submatches?&nbsp;starts-line?&nbsp;ends-line?</I>)</CODE><A NAME="3">&nbsp;</A>
<BR><CODE>    -&gt;&nbsp;<I>boolean or list of matches</I></CODE>
<LI><CODE>(match?<I>&nbsp;x</I>)&nbsp;-&gt;&nbsp;<I>boolean</I></CODE><A NAME="4">&nbsp;</A>
<LI><CODE>(match-start<I>&nbsp;match</I>)&nbsp;-&gt;&nbsp;<I>integer</I></CODE><A NAME="5">&nbsp;</A>
<LI><CODE>(match-end<I>&nbsp;match</I>)&nbsp;-&gt;&nbsp;<I>integer</I></CODE><A NAME="6">&nbsp;</A>
</UL>
<CODE>Regexp-match</CODE> matches the regular expression against the characters
 in <CODE><I>string</I></CODE>, starting at position <CODE><I>start</I></CODE>.
If the string does not match the regular expression, <CODE>regexp-match</CODE>
 returns <CODE>#f</CODE>.
If the string does match, then a list of match records is returned
 if <CODE><I>submatches?</I></CODE> is true, or <CODE>#t</CODE> is returned if it is not.
Each match record contains the index of the character at the beginning
 of the match and one more than the index of the character at the end.
The first match record gives the location of the substring that matched
 <CODE><I>regexp</I></CODE>.
If the pattern in <CODE><I>regexp</I></CODE> contained submatches, then the results
 of these are returned in order, with a match records reporting submatches
 that succeeded and <CODE>#f</CODE> in place of those that did not.
<P><CODE><I>Starts-line?</I></CODE> should be true if <CODE><I>string</I></CODE> starts at the beginning
 of a line and <CODE><I>ends-line?</I></CODE> should be true if it ends one.
<P><P>
  
Previous: <A HREF="s48manual_87.html">Regular expressions</A> | Next: <A HREF="s48manual_87.html">Regular expressions</A></BODY></HTML>
